﻿using CompanyManagement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace CompanyManagement.Services
{
    /// <summary>
    /// Summary description for CompanyServices
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class CompanyServices : System.Web.Services.WebService
    {
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod]
        public List<string> GetCompany(string txt)
        {
            List<string> models = new List<string>();
            var companylist = new CompanyDAO().GetCompanies().Where(p => Tools.RemoveDiacritics(p.Name).Contains(txt)).ToList();
            companylist.ForEach(x => models.Add(string.Format("{0}, {1}", x.CompanyNo, x.Name)));
            return models;
        }
    }
}
